﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class MacroParameter : SourceNode
{
    private readonly SourceNode _nameNode;

    internal MacroParameter(SourceNode? parent, SourceNode nameNode) :
        base(parent, SyntaxKinds.MacroParameterDeclaration)
    {
        SetChildField(ref _nameNode, nameNode);
    }


    public string Name => _nameNode.Text;

    public SourceNode NameNode => _nameNode;

    public bool IsVaArgs => NameNode.IsNode(SyntaxKinds.DotDotDotToken);

    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, NameNode);
    }
}


public static partial class NodeFactory
{
    public static MacroParameter CreateMacroParameter(SourceNode? parent, SourceNode nameNode)
    {
        Debug.Assert(nameNode.IsIdentifier || nameNode.IsNode(SyntaxKinds.DotDotDotToken));
        return new MacroParameter(parent, nameNode);
    }
}